package cn.tedu.sp04.controller;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.web.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    //获取订单
    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId){
        Order order = orderService.getOrder(orderId);
        return JsonResult.build().code(200).data(order);
    }

    //添加订单
    @PostMapping("/add")
//    public JsonResult<?> add(@RequestBody Order order){  先写死
    public JsonResult<?> add(){
        Order order = new Order("agdfas54546af",
                Arrays.asList(new Item[]{}),
                new User(8, null, null));
        orderService.addOrder(order);
        return JsonResult.build().code(200).msg("添加订单成功");
    }

    //处理浏览器自动请求的图标
    @GetMapping("/favicon.ico")
    public void ico(){

    }


}
